import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';

class RideTopicWidget extends StatefulWidget {
  const RideTopicWidget({Key? key}) : super(key: key);

  @override
  State<RideTopicWidget> createState() => _RideTopicWidgetState();
}

class _RideTopicWidgetState extends State<RideTopicWidget> {
  // RideTopicData? _topicData;
  Timer? _timer;
  // PageController? _pageController;
  var _index = 0;

  Future<void> _loadData() async {
    // var result = await AutoRideApi.instance.topics();

    // if (result.isSuccess) {
    //   _topicData = result.data;
    //   // _pageController = PageController();
    //   if (mounted) setState(() {});
    //   _timer = Timer.periodic(const Duration(seconds: 10), (timer) {
    //     _index = Random().nextInt(topics.length);
    //     if (mounted) setState(() {});
    //     // _index++;
    //     //
    //     // _pageController?.animateToPage(_index, duration: Duration(milliseconds: 300), curve: Curves.linear);
    //     // if (_index >= contentStrs.length - 1) {
    //     //   _index = 0;
    //     //   _pageController?.jumpToPage(0);
    //     // }
    //   });
    // }
  }

  @override
  void initState() {
    super.initState();
    _loadData();
  }

  // List<String> get topics => _topicData?.topic ?? [];

  // List<String> get contentStrs => topics.length > 1 ? [...topics, topics.first] : topics;

  // Widget get title => Text(
  //       T.current!.df_cheats,
  //       style: TextStyle(color: Color(0xFFFFD400), fontSize: 11),
  //     );
  // int get index => min(_index, topics.length - 1);
  // Widget get content => MarqueeText(
  //     text: _topicData?.topic[index] ?? '',
  //     style: const TextStyle(color: Colors.white, fontSize: 11));

  // Widget get content => PageView.builder(
  //   controller: ,
  //   itemCount: _topicData?.topic.length??0,
  //     itemBuilder: (context, index) => Text(_topicData?.topic[index]??'', style: const TextStyle(color: Colors.white, fontSize: 11)),
  // );

  // Widget get body => RichText(
  //   maxLines: 1,
  //     text: TextSpan(
  //         text: T.current!.df_cheats,
  //         style: const TextStyle(color: Color(0xFFFFD400), fontSize: 11),
  //       children: [
  //         TextSpan(
  //           text: _topicData?.topic[index]??'',
  //             style: const TextStyle(color: Colors.white, fontSize: 11)
  //         )
  //       ]
  //     )
  // );

  // Widget get body => Row(
  //       mainAxisSize: MainAxisSize.min,
  //       children: [title, content],
  //     );

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 22,
      constraints: const BoxConstraints(
        maxWidth: 253,
      ),
      padding: const EdgeInsets.symmetric(horizontal: 16),
      decoration: const ShapeDecoration(
          color: Color(0x1EDFD6FF), shape: StadiumBorder()),
      child: Container(
        color: Colors.green,
        height: 40,
        width: 40,
      ),
    );
  }

  @override
  void dispose() {
    _timer?.cancel();
    _timer = null;
    super.dispose();
  }
}
